package com.hframe.typefilter;

import com.hframe.utils.BytesUtils;
import org.apache.log4j.Logger;


/**
 * ID 加密
 *
 * @author Administrator
 */
public class LongBase64Encoder implements FilterRef<String, Object> {
    static Logger log = Logger.getLogger(LongBase64Encoder.class);

    @Override
    public String filter(Object object) {
        if (null != object) {
            if (object instanceof Long) {
                return encoder((long) object);
            } else if (object instanceof String) {
                return encoder(Long.parseLong((String) object));
            }
        }
        return null;
    }

    public static String encoder(Long id) {
        if (null == id)
            return null;
        byte[] data = new byte[8];
        BytesUtils.putLong(data, id, 0);
        return Base64Encoder.encoder(data);
    }
}